home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
dde2
/
ddexl.frm
< prev
next >
Wrap
Text File
|
1993-05-16
|
4KB
|
165 lines
VERSION 2.00
Begin Form Form1
Caption = "DDE Client to Excel"
ClientHeight = 4290
ClientLeft = 1320
ClientTop = 1785
ClientWidth = 7245
Height = 4695
Left = 1260
LinkMode = 1 'Source
LinkTopic = "Form1"
ScaleHeight = 4290
ScaleWidth = 7245
Top = 1440
Width = 7365
Begin TextBox Text1
Height = 1095
Left = 600
MultiLine = -1 'True
TabIndex = 0
Text = "Data"
Top = 1200
Width = 2175
End
Begin CommandButton Command2
Caption = "Manual Link / Update"
Height = 375
Left = 3600
TabIndex = 2
Top = 1200
Width = 2235
End
Begin CommandButton Command1
Caption = "Auto Link"
Height = 375
Left = 3600
TabIndex = 1
Top = 1800
Width = 2265
End
Begin CommandButton Command4
Caption = "Poke"
Height = 375
Left = 3600
TabIndex = 3
Top = 2400
Width = 2280
End
Begin TextBox Text2
Height = 720
Left = 570
MultiLine = -1 'True
ScrollBars = 1 'Horizontal
TabIndex = 4
Text = "Open Documents"
Top = 2760
Width = 2265
End
Begin CommandButton Command3
Caption = "Get Document Names"
Height = 450
Left = 3600
TabIndex = 5
Top = 3000
Width = 2415
End
Begin Label Label1
Alignment = 2 'Center
AutoSize = -1 'True
BorderStyle = 1 'Fixed Single
Caption = "This form links to a document SERVER.XLS. Excel is executed and the document is opened if necessary."
Height = 615
Left = 1440
TabIndex = 6
Top = 240
Width = 3945
WordWrap = -1 'True
End
End
Option Explicit
Const NONE = 0 ' 0 - None
Const LINK_SOURCE = 1 ' 1 - Source (forms only)
Const LINK_AUTOMATIC = 1 ' 1 - Automatic (controls only)
Const LINK_MANUAL = 2 ' 2 - Manual (controls only)
Const LINK_NOTIFY = 3 ' 3 - Notify (controls only)
Sub Command1_Click ()
Text1.LinkMode = NONE
Text1.LinkMode = LINK_AUTOMATIC
End Sub
Sub Command2_Click ()
Text1.LinkMode = NONE
Text1.LinkMode = LINK_MANUAL
Text1.LinkRequest
End Sub
Sub Command3_Click ()
text2.LinkMode = NONE
text2.LinkTopic = "Excel|system"
text2.LinkItem = "topics"
text2.LinkMode = LINK_MANUAL
text2.LinkRequest
End Sub
Sub Command4_Click ()
Text1.LinkMode = NONE
Text1.LinkMode = LINK_MANUAL
Text1.LinkPoke
End Sub
Sub Form_Load ()
Dim rc As Integer
Dim IsOpen As Integer
Dim TheCmd As String
'Test to see if App is running...
On Error GoTo startup
reentry:
Text1.LinkMode = NONE
Text1.LinkTopic = "Excel|System"
Text1.LinkItem = "Topics"
Text1.LinkMode = LINK_MANUAL
Text1.LinkRequest
Text1.LinkTimeout = 300
'The linkitem TOPICS returns a list of all open spreadsheets
'Test if sheet is open.
IsOpen = InStr(UCase$(Text1.Text), UCase$("source.xls"))
text2.Text = Str$(IsOpen)
If IsOpen = 0 Then
'Document is not open
On Error GoTo nosheet
TheCmd = "[OPEN(" + """"
TheCmd = TheCmd$ + "c:\vbdemos\dde\source.xls" + """" + ",1)]"
Text1.LinkExecute TheCmd
End If
'Set link to correct row/cell location
Text1.LinkMode = NONE
Text1.LinkTopic = "Excel|SOURCE.XLS"
Text1.LinkItem = "R1C1"
Text1.LinkMode = LINK_AUTOMATIC
Exit Sub
startup:
If Err = 282 Then
rc = Shell("c:\excel\Excel c:\vbdemos\dde\source.xls", 7)
Resume reentry
Else
MsgBox "Unknown DDE error."
Exit Sub
End If
nosheet:
MsgBox "Unable to open sheet."
Exit Sub
End Sub